var express = require('express');
var router = express.Router();
const { getCustomers, addCustomers, delCustomers, getCustomerById, changeCustomers, getCustomerBySalesMen, CustomersLogin } = require('../service/customersService')
    //查看所有客户信息
router.get('/getCustomers', async function(req, res, next) {
    const { pageSize, cutPage, type, value } = req.query;
    const customers = await getCustomers(pageSize, cutPage, type, value);
    res.send(customers)
});
//新增客户
router.post('/addCustomers', async function(req, res, next) {
    const { account, password, name, age, gender, phone, salesMenId } = req.body;
    const result = await addCustomers(account, password, name, age, gender, phone, salesMenId);
    res.send(result)
});
//删除客户
router.post('/delCustomers', async function(req, res, next) {
    const { _id } = req.body;
    const result = await delCustomers(_id);
    res.send(result)
});
//查看销售员负责的所有客户
router.get('/getCustomerBySalesMen', async function(req, res, next) {
    const { salesMenId, pageSize, cutPage, type, value } = req.query;
    const result = await getCustomerBySalesMen(salesMenId, pageSize, cutPage, type, value);
    res.send(result)
});
//查看单个客户信息
router.get('/getCustomerById', async function(req, res, next) {
    const { _id } = req.query;
    const result = await getCustomerById(_id);
    res.send(result)
});
//修改客户信息
router.post('/changeCustomers', async function(req, res, next) {
    const { _id, account, password, name, age, gender, phone, salesMenId } = req.body;
    const result = await changeCustomers(_id, account, password, name, age, gender, phone, salesMenId);
    res.send(result)
});
//客户登录
router.post('/CustomersLogin', async function(req, res, next) {
    const { account, password } = req.body;
    const result = await CustomersLogin(account, password);
    res.send(result)
});
module.exports = router;